﻿using System;

namespace AbpRabbitMqDemo
{
    using System.Threading;

    using Abp;
    using Abp.Dependency;
    using Abp.Events.Bus;
    using Abp.Events.Bus.Handlers;

    using AbpRabbitMqAppOne;

    class Program
    {
        static void Main(string[] args)
        {
            var abpBoot = AbpBootstrapper.Create<RabbitMqTestAppOneModule>();
            abpBoot.Initialize();

            var eventbus = abpBoot.IocManager.Resolve<IEventBus>();


            eventbus.Trigger(new TestEventData());


            Thread.Sleep(10 * 1000);

            eventbus.Trigger(new TestEventData()
                                 {
                                     Message = "10秒后的事件"
                                 });


            Console.WriteLine("Hello World!");
            Console.ReadKey(true);
        }
        
        public class TestEventData : EventData
        {
            public string Message { get; set; }
        }
        
        public class TestEventDataHandler : IEventHandler<TestEventData>, ITransientDependency
        {
            public void HandleEvent(TestEventData eventData)
            {
                Console.WriteLine($"处理事件{eventData.GetType().Name},事件内容:{eventData.Message}");
            }
        }
    }
}
